package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.DingdingDayRequest;
import cn.stylefeng.guns.sys.modular.system.mapper.DingdingDayRequestMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.DingdingDayRequestParam;
import cn.stylefeng.guns.sys.modular.system.model.result.DingdingDayRequestResult;
import  cn.stylefeng.guns.sys.modular.system.service.DingdingDayRequestService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 钉钉，人员申请单，请假、外出的表单 服务实现类
 * </p>
 *
 * @author zxd
 * @since 2022-03-10
 */
@Service
public class DingdingDayRequestServiceImpl extends ServiceImpl<DingdingDayRequestMapper, DingdingDayRequest> implements DingdingDayRequestService {
    @Resource
    private DingdingDayRequestMapper dingdingDayRequestMapper;

    @Override
    public void add(DingdingDayRequestParam param){
        DingdingDayRequest entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(DingdingDayRequestParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(DingdingDayRequestParam param){
        DingdingDayRequest oldEntity = getOldEntity(param);
        DingdingDayRequest newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public DingdingDayRequestResult findBySpec(DingdingDayRequestParam param){
        return null;
    }

    @Override
    public List<DingdingDayRequestResult> findListBySpec(DingdingDayRequestParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(DingdingDayRequestParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(DingdingDayRequestParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private DingdingDayRequest getOldEntity(DingdingDayRequestParam param) {
        return this.getById(getKey(param));
    }

    private DingdingDayRequest getEntity(DingdingDayRequestParam param) {
        DingdingDayRequest entity = new DingdingDayRequest();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Override
    public void batchInsert(List list) {
        dingdingDayRequestMapper.batchInsert(list);
    }
}
